<?php

use console\db\channels\TransferTableMigration;
use common\helpers\IpHelper;
use yii\db\Query;

/**
 * 用户签到信息转移
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300030_000040_t_signin extends TransferTableMigration {

    /**
     * @inheritdoc
     */
    public $sourceDb = 'olddb';

    /**
     * @inheritdoc
     */
    public function buildQuery() {
        $columns = [
            'uid',
            'inputtime',
            'ipaddress',
            'continuation',
        ];
        return (new Query())->from('{{%' . $this->sourceTable . '}}')->select($columns)->orderBy('inputtime asc');
    }

    /**
     * @inheritdoc
     */
    public function getTransferOptions() {
        return [
            'table' => [
                'user_signin_log' => 'member_checkin',
            ],
            'columns' => [
                'user_id' => 'uid',
                'created_at' => 'inputtime',
                'ip' => function ($data) {
                    return IpHelper::ip2long($data['ipaddress']);
                },
                'serial' => 'continuation'
            ],
        ];
    }

}
